package com.feinno.module.security.web;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.feinno.framework.common.web.AbstractController;
import com.feinno.module.security.SecurityConstants;
import com.feinno.module.security.domain.Menu;
import com.feinno.module.security.service.MenuService;
import com.google.common.collect.Lists;

@Controller
@RequestMapping(value = "/admin/system/menu")
public class MenuController extends AbstractController<Menu, MenuService> {
	
	@Autowired
	@SuppressWarnings("unused")
	private MenuService menuService;

	private List<String> allIcons = null;
	private Object iconLoading = new Object();

	@Override
	protected void referenceData(HttpServletRequest request, Map<String, Object> model) {
		synchronized (iconLoading) {
			if (allIcons == null) {
				String menuIcons = SecurityConstants.FRAMWORK_MENU_ICON_FILES;
				List<String> files = Lists.newArrayList(menuIcons.split("\\|"));
				allIcons = new ArrayList<String>(files.size());
				for (String file : files) {
					allIcons.add(SecurityConstants.FRAMWORK_MENU_ICON_PATH + file);
				}
			}
		}
		model.put("allIcons", allIcons);
	}

}
